﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Configuration;
using CacheInterfaceLib;

namespace CacheServer
{
    partial class CacheWinService : ServiceBase
    {
        public CacheWinService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            try
            {
                TcpChannel port = new TcpChannel(Convert.ToInt32(ConfigurationManager.AppSettings["PortNumber"]));
                ChannelServices.RegisterChannel(port, false);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(ICacheService), "CacheServices", WellKnownObjectMode.Singleton);
                RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
                RemotingConfiguration.CustomErrorsEnabled(false);
            }
            catch (Exception)
            {
                throw;
            }
        }

        protected override void OnStop()
        {
            // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
        }
    }
}
